package com.jxmdkt.controller;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;

import com.jfinal.core.Controller;


public class MessageController extends Controller {
	
	public void index() {
		
		//String signature=getPara("signature");
		String timestamp=getPara("timestamp");
		String nonce=getPara("nonce");
		String echostr=getPara("echostr");
		String token="13695_t";
		String[] strings=new String[]{token,nonce,timestamp};
		ArrayList<String> list = new ArrayList<String>();  
		  list.add(token);  
		  list.add(nonce);  
		  list.add(timestamp);  
		  Collections.sort(list);  
		  String s ="";
		 for (int i = 0; i < strings.length; i++) {
			s+=strings[i];
			
		}
		 System.out.println(s);
		s=SHA1(s);
		System.out.println(s);
			keepPara("echostr");
			renderText(echostr);
		
	}
	public  String SHA1(String decript) {
	        try {
	            MessageDigest digest = java.security.MessageDigest
	                    .getInstance("SHA-1");
	            digest.update(decript.getBytes());
	            byte messageDigest[] = digest.digest();
	            StringBuffer hexString = new StringBuffer();
	            for (int i = 0; i < messageDigest.length; i++) {
	                String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
	                if (shaHex.length() < 2) {
	                    hexString.append(0);
	                }
	                hexString.append(shaHex);
	            }
	            return hexString.toString();
	 
	        } catch (NoSuchAlgorithmException e) {
	            e.printStackTrace();
	        }
	        return "";
	    }
}
